package com.qingcloud.base.utils;

import java.util.HashMap;
import java.util.Map;

public class CommonUtils {

    /**
     * Cookies 解析
     * @param value
     * @return
     */
    public static Map<String,String> cookieToMap(String value) {
        Map<String, String> map = new HashMap<String, String>();
        if(value==null) return null;
        value = value.replace(" ", "");
        if (value.contains(";")) {
            String[]  values= value.split(";");
            for (String val : values) {
                String[] vals = val.split("=");
                if(vals.length>=2 && vals[0] !=  null && vals[1] != null) {
                    map.put(vals[0], vals[1]);
                }
            }
        } else {
            String values[] = value.split("=");
            if(values.length>=2 && values[0] !=  null && values[1] != null) {
                map.put(values[0], values[1]);
            }
        }
        return map;
    }
}
